<?php
require_once(dirname(__FILE__)."/../core/safeParam.php");
class module
{
  function menusItemAdd($vars, $files)
  {
    global $database;
    $mid         = $vars['mid'];
    $name        = $vars['name'];
    $menu        = $vars['menu'];
    $cat         = $vars['cat'];
    $description = $vars['description'];
    $feature     = $vars['feature'];
    $type1       = $vars['type1'];
    $code        = $vars['code'];
    $price       = serialize($vars['price']);
    $rid         = $vars['rid'];
    if ($files['image']['size'] != 0) {
      $image       = uploadImage($files, '300', '300', '../UserFiles/Image/product_photos/', 'image');
      $image_thumb = uploadImage($files, '80', '80', '../UserFiles/Image/product_photos/thumbs/', 'image');
    } //$files['image']['size'] != 0
    $options = serialize($vars['options']);
    $query   = $database->insert("pizza_feasts_items", "name, mid, description, price, feature, cat,type1,code,options,image,rid", "'$name', '$mid', '$description', '$price', '$feature', '$cat', '$type1', '$code', '$options', '$image','$rid'");
    $id      = $database->insertid();
    header('location: ../admin/index.php?edit=pizza-feasts&update=1');
  }
  // ==================================================================
  // We would like to modify item to a category
  function menusItemModify($vars, $files)
  {
    global $database;
    $mid         = $vars['cat'];
    $price       = serialize($vars['price']);
    $options     = serialize($vars['options']);
    $id          = $vars['id'];
    $name        = $vars['name'];
    $menu        = $vars['menu'];
    $description = $vars['description'];
    $feature     = $vars['feature'];
    $type1       = $vars['type1'];
    $code        = $vars['code'];
    if ($files['image']['size'] != 0) {
      $image       = uploadImage($files, '300', '300', '../UserFiles/Image/product_photos/', 'image');
      $image_thumb = uploadImage($files, '80', '80', '../UserFiles/Image/product_photos/thumbs/', 'image');
      $query       = $database->update("pizza_feasts_items", "name = '$name', description = '$description', price = '$price', type1 = '$type1', code = '$code', options = '$options', image = '$image'", "id = '$id'");
    } //$files['image']['size'] != 0
    else {
      $query = $database->update("pizza_feasts_items", "name = '$name', description = '$description', price = '$price', type1 = '$type1', code = '$code', options = '$options'", "id = '$id'");
    }
    header('location: ../admin/index.php?edit=pizza-feasts&update=1');
  }
  // ==================================================================
  // Delete a menu item to a category
  function menusItemDelete($vars)
  {
    global $database;
    $mid    = $vars['mid'];
    $itemid = $vars['itemid'];
    $menu   = $vars['return'];
    $cat    = $vars['return2'];
    $query  = $database->delete("pizza_feasts_items", "id = '$itemid'");
    header('location: ../admin/index.php?edit=pizza-feasts&update=1');
  }
  function pizzaAdd($vars)
  {
    global $database;
    $name          = $vars['name'];
    $size          = $vars['size'];
    $price         = $vars['price'];
    $topping_price = $vars['topping_price'];
    $toppings      = $vars['toppings'];
    $base          = $vars['base'];
    $max_toppings  = $vars['max_toppings'];
    $half          = $vars['half'];
    $tier_amount   = $vars['tier_amount'];
    $tier_price    = $vars['tier_price'];
    $discount      = $vars['discount'];
    $free_topping  = $vars['free_topping'];
    $meat_toppings = $vars['meat_toppings'];
    $topoff        = $vars['topoff'];
    if ($vars['sides'][0] == "") {
      $sides[0] = 0;
    } //$vars['sides'][0] == ""
    else {
      $sides[0] = 1;
    }
    if ($vars['sides'][1] == "") {
      $sides[1] = 0;
    } //$vars['sides'][1] == ""
    else {
      $sides[1] = 1;
    }
    if ($vars['sides'][2] == "") {
      $sides[2] = 0;
    } //$vars['sides'][2] == ""
    else {
      $sides[2] = 1;
    }
    if ($vars['sides'][3] == "") {
      $sides[3] = 0;
    } //$vars['sides'][3] == ""
    else {
      $sides[3] = 1;
    }
    $sides = serialize($sides);
    $rid   = $vars['rid'];
    $query = $database->insert("pizza_feasts", "name,size,price,topping_price,toppings,rid,base,max_toppings,half,tier_amount,tier_price,discount,meat_toppings,topoff,sides,free_topping", "'$name', '$size', '$price', '$topping_price', '$toppings', '$rid', '$base', '$max_toppings', '$half', '$tier_amount', '$tier_price', '$discount', '$meat_toppings', '$topoff', '$sides', '$free_topping'");
    header('location: ../admin/index.php?edit=pizza-feasts&update=1');
  }
  // ==================================================================
  // We would like to modify the menu
  function pizzaEdit($vars)
  {
    global $database;
    $id            = $vars['id'];
    $name          = $vars['name'];
    $size          = $vars['size'];
    $price         = $vars['price'];
    $topping_price = $vars['topping_price'];
    $toppings      = $vars['toppings'];
    $base          = $vars['base'];
    $max_toppings  = $vars['max_toppings'];
    $half          = $vars['half'];
    $tier_amount   = $vars['tier_amount'];
    $tier_price    = $vars['tier_price'];
    $discount      = $vars['discount'];
    $free_topping  = $vars['free_topping'];
    $meat_toppings = $vars['meat_toppings'];
    $topoff        = $vars['topoff'];
    if ($vars['sides'][0] == "") {
      $sides[0] = 0;
    } //$vars['sides'][0] == ""
    else {
      $sides[0] = 1;
    }
    if ($vars['sides'][1] == "") {
      $sides[1] = 0;
    } //$vars['sides'][1] == ""
    else {
      $sides[1] = 1;
    }
    if ($vars['sides'][2] == "") {
      $sides[2] = 0;
    } //$vars['sides'][2] == ""
    else {
      $sides[2] = 1;
    }
    if ($vars['sides'][3] == "") {
      $sides[3] = 0;
    } //$vars['sides'][3] == ""
    else {
      $sides[3] = 1;
    }
    $sides = serialize($sides);
    $query = $database->update("pizza_feasts", "name = '$name' , price = '$price', size = '$size', topping_price = '$topping_price', toppings = '$toppings', base = '$base', max_toppings = '$max_toppings', half = '$half' , tier_amount = '$tier_amount' , tier_price = '$tier_price', discount = '$discount' , meat_toppings = '$meat_toppings', topoff = '$topoff', sides = '$sides', free_topping = '$free_topping' ", "id = '$id'");
    header('location: ../admin/index.php?edit=pizza-feasts&update=1');
  }
}
?>
